#!/bin/bash

# The following variable definitions should match the variables in process
# startup script. When making changes to either the startup or cleanup script,
# grep and replace for these changes in the other script if appropriate.

java_base=com.citusdata.elven.feeder
lookout_base=system_stats.pl
for cleanup_process in ${java_base} ${lookout_base}
do
  # For details on the following command, see Advanced Bash-Scripting Guide,
  # Example 15-7 at http://tldp.org/LDP/abs/html/moreadv.html#KILLBYNAME
  ps ax | grep ${cleanup_process} | awk '{print $1}' | xargs -i kill {} 2&>/dev/null
done

bdb_dir=/mnt/sdd/bdb
bdb_backup_dir=/mnt/sdd/bdb-backup

if [[ -n "$1" && "$1" == "full_clean" ]]; then
  bdb_dirs="${bdb_dir} ${bdb_backup_dir}"
else
  bdb_dirs=${bdb_dir}
fi

linearroad_dirs="/mnt/sdb/input/linearroad /mnt/sdc/output/linearroad"
ec2_historical_file="/mnt/sdb/historical/historical-tolls.out.ec2"
log_files="/home/elven/logs/* /home/elven/remote.out /home/lookout/remote.out"

for cleanup_file in ${bdb_dirs} ${linearroad_dirs} \
                    ${ec2_historical_file} ${log_files}
do rm -rf ${cleanup_file}; done
